#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 250010;

int n,s,t,dis[N],h[N],cnt;
bool vis[N];
struct edge{int v,w,nxt;}e[N<<3];
void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;}

int id(int x,int y){return (x - 1) * n + y;}

void dijk(){
	memset(dis,0x3f,sizeof(dis)); dis[s] = 0; priority_queue<pii> q;
	q.push(pii(0,s));
	while(q.size()){
		int x = q.top().se; q.pop(); if(vis[x]) continue;
		for(int i = h[x],y;i;i = e[i].nxt){
			if(dis[y = e[i].v] > dis[x] + e[i].w){
				dis[y] = dis[x] + e[i].w; q.push(pii(-dis[y],y));
			}
		}
	}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; s = 0; t = n * n + 1;
	for(int i = 1;i <= n+1;i++)
		for(int j = 1;j <= n;j++){
			int x = in;
			if(i == 1) link(s,id(i,j),x);
			else if(i == n + 1) link(id(i-1,j),t,x);
			else link(id(i-1,j),id(i,j),x);
		}
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n + 1;j++){
			int x = in;
			if(j == 1) link(id(i,j),t,x);
			else if(j == n + 1) link(s,id(i,j-1),x);
			else link(id(i,j),id(i,j-1),x);
		}
	for(int i = 1;i <= n + 1;i++)
		for(int j = 1;j <= n;j++){
			int x = in;
			if(i == 1) link(id(i,j),s,x);
			else if(i == n + 1) link(t,id(i-1,j),x);
			else link(id(i,j),id(i-1,j),x);
		}
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n + 1;j++){
			int x = in;
			if(j == 1) link(t,id(i,j),x);
			else if(j == n + 1) link(id(i,j-1),s,x);
			else link(id(i,j-1),id(i,j),x);
		}
	dijk();
	printf("%d\n",dis[t]);
	return 0;
}

